package com.itcast.donkey.adapters;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itcast.donkey.R;
import com.itcast.donkey.activity.TravelInItemActiity;
import com.itcast.donkey.modles.TravelInHeadImageModels;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lanouhn on 16/9/12.
 */
public class TravelInHeadAdapter extends RecyclerView.Adapter<TravelInHeadAdapter.ItemViewHolder> {
    private Context context;
    private TravelInHeadImageModels HeadImageModels;

    public TravelInHeadAdapter(Context context, TravelInHeadImageModels headImageModels) {
        this.context = context;
        HeadImageModels = headImageModels;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_in_head_top, null);
        ItemViewHolder holder = new ItemViewHolder(view);
        return holder;
    }


    @Override
    public void onBindViewHolder(ItemViewHolder holder, int position) {
        Picasso.with(context).load(HeadImageModels.getImage()).into(holder.headImage);
        holder.userNameTop.setText(HeadImageModels.getName());
        holder.userName.setText(HeadImageModels.getName());
        if (HeadImageModels.getGender() == 1) {
            holder.userSexMale.setVisibility(View.VISIBLE);
            holder.userSexFemale.setVisibility(View.GONE);
        } else {
            holder.userSexMale.setVisibility(View.GONE);
            holder.userSexFemale.setVisibility(View.VISIBLE);
        }
        holder.userLevel.setText(HeadImageModels.getTrips_count() + "篇游记");
        holder.logo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((Activity) context).finish();
            }
        });

    }


    @Override
    public int getItemCount() {
        return 1;
    }

    public class ItemViewHolder extends RecyclerView.ViewHolder {
        private LinearLayout linTop;
        private ImageView backScenicApot;
        private ImageView logo;
        private RelativeLayout relBottom;
        private ImageView headImage;
        private TextView userName;
        private ImageView userSexMale;
        private ImageView userSexFemale;
        private TextView userLevel;
        private TextView userNameTop;

        public ItemViewHolder(View itemView) {
            super(itemView);
            linTop = (LinearLayout) itemView.findViewById(R.id.lin_top);
            backScenicApot = (ImageView) itemView.findViewById(R.id.back_scenic_apot);
            logo = (ImageView) itemView.findViewById(R.id.logo);
            relBottom = (RelativeLayout) itemView.findViewById(R.id.rel_bottom);
            headImage = (ImageView) itemView.findViewById(R.id.head_image);
            userNameTop = (TextView) itemView.findViewById(R.id.user_name_top);
            userName = (TextView) itemView.findViewById(R.id.user_name);
            userSexMale = (ImageView) itemView.findViewById(R.id.user_male_sex);
            userSexFemale = (ImageView) itemView.findViewById(R.id.user_female_sex);
            userLevel = (TextView) itemView.findViewById(R.id.user_level);

        }
    }
}
